package controler;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JComboBox;

import main.Game;
import model.Card;
import model.City;
import view.Card_board_view;

public class CardBoxListener implements ActionListener{
	Card_board_view cbv;
	Game game;

	public CardBoxListener(Card_board_view cbv,Game g) {
		this.cbv=cbv;
		this.game=g;
	}

	public void actionPerformed(ActionEvent e) {
		JComboBox<String>players=(JComboBox<String>) e.getSource();
		ArrayList<Card>c1=new ArrayList<>(); 
		System.out.println(players.getSelectedItem());
		if(players.getSelectedItem().equals("bank")){
			c1=game.bank.city;
		}
		else{
			for(int i=0;i<game.listPlayer.size();i++){
				if(game.listPlayer.get(i).getName().equals(players.getSelectedItem())){
					c1 = game.listPlayer.get(i).getAllCards();
				}
			}
		}
		cbv.c.clear();
		for(int i=0;i<c1.size();i++){
			cbv.c.add((City)c1.get(i));
		}
		cbv.view();
		cbv.revalidate();
	}
}
